<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户注册</title>
<link href="file/images/yc.png" rel="shortcut icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="./file/css/reg.css"/>
</head>
	<body style="background-image: url(file/images/7.jpg);">
		<a href="index.html"><img src="file/images/11.png" title="首页" width="600px" height="700px"></a>
		<div class="box">      
		<h2>用户注册  </h2>
		<form >
			<div class="inputBox"><input type = "text" name= "nickname" id="nickname" required=""/><label>请输入用户名：</label></div>
			<div class="inputBox"><input type = "password" name= "pwd" id="pwd" required=""/><label>请输入密码：</label></div>
			<div class="inputBox"><input type = "password" name= "repwd" id="repwd" required=""/><label>请再次输入密码：</label></div>
			<div class="inputBox"><input type = "text" name= "tel" id="tel" required=""/><label>请输入手机号码：</label></div>
			<div class="inputBox"><input type = "text" name= "email" id="email" required=""/><label>请输入电子邮箱：</label></div>	
			<div align="center"><input type="button" value="注册" onclick="reg()"/></div>
		</form>
		</div>

	<script src="file/js/jquery-3.4.1.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		function reg(){
			let nickname = $("#nickname").val();
			let pwd = $("#pwd").val();
			let repwd = $("#repwd").val();
			let tel = $("#tel").val();
			let email = $("#email").val();
			if(pwd != repwd){
				alert("两次输入的密码不一致！");
				return;
			}

			$.ajax({
				url:"/register",
				type:"POST",
				data:{
					nickname:"nickname="+nickname,
					pwd:"pwd="+pwd,
					tel:"tel="+tel,
					email:"email="+email
				},
				success:function (data){
					console.log(data)
					if(data.code==1){
						alert(data.message);
						location.href= "loginPage.html";
					}else if(data.code==2){
						alert(data.message);
						return;
					}else{
						alert("发生未知异常！");
						return;
					}

				}
			});
		}
	
	</script>
	
</body>
</html>